package org.kiwi.job.util;

import groovy.lang.Binding;
import groovy.lang.GroovyShell;

/**
 * @email jack.liu.19910921@gmail.com
 * Created by jack on 17/2/21.
 */
public class GroovyShellUtil {

    private static final GroovyShell GROOVY_SHELL;

    static {
        GROOVY_SHELL = new GroovyShell(new Binding());
    }

    public static Object evaluate(String script) {
        return GROOVY_SHELL.evaluate(script);
    }

    private static final String SCRIPT = "import java.util.Calendar;int jobSatus = 1;Calendar now = Calendar.getInstance();int hourOfDay = now.get(Calendar.HOUR_OF_DAY);int dayOfWeek = now.get(Calendar.DAY_OF_WEEK);if (dayOfWeek == 3) {if (hourOfDay <= 17) jobSatus = 0;}\n return jobSatus;\n";

    public static void main(String[] args) {
        System.out.println(evaluate(SCRIPT));
    }

}
